﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Windows.Navigation;
using System.IO;
using System.Windows.Media.Imaging;
using System.Text.RegularExpressions;
using System.Xml.Linq;
using System.ComponentModel;
using System.Collections.ObjectModel;
using System.Threading;
using TED.Model;
using TED.ViewModels;
using System.IO.IsolatedStorage;
using System.Xml;

namespace TED
{
    public partial class MainPage : PhoneApplicationPage
    {
        private SyncJobsClass SyncJobs;
        private List<string> contextMenuHeader = new List<string> { "abc", "def" };
        

        // Constructor
        public MainPage()
        {
            InitializeComponent();
            SyncJobs = new SyncJobsClass();
            //DataContext = App.ViewModel;
            this.Loaded +=new RoutedEventHandler(MainPage_Loaded);
        }

        // Load data for the ViewModel Items
        private void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            ItemViewOnPage.DataContext = SyncJobs.Items;
            SyncJobs.ElementFinished += new SyncJobsClass.ElementFinishedDelegate(SyncJobs_ElementFinished);
            SyncJobs.WorkFinished += new SyncJobsClass.WorkFinishedDelegate(SyncJobs_WorkFinished);
            this.ProgressBarIsBusy(false);
            SyncJobs.Parse();
        }
        
        void SyncJobs_WorkFinished(bool success)
        {
            this.ProgressBarIsBusy(false);
        }

        void SyncJobs_ElementFinished()
        {
            this.LoadingTextBlock.Visibility = Visibility.Collapsed;
        }

        void ProgressBarIsBusy(Boolean isBusy)
        {
            this.performanceProgressBarCustomized.IsIndeterminate = isBusy;
            this.performanceProgressBarCustomized.Visibility = isBusy ? Visibility.Visible : Visibility.Collapsed;
        }

        private void ViewFavoriteVideos_Click(object sender, EventArgs e)
        {
            NavigationService.Navigate(new Uri("/View/Favourite.xaml", UriKind.Relative));
        }

        private void ViewSearchPage_Click(object sender, EventArgs e)
        {
            NavigationService.Navigate(new Uri("/View/SearchPage.xaml", UriKind.Relative));
        }

        private void PlayVideoFromPlayList_Click(object sender, EventArgs e)
        {
            this.NavigationService.Navigate(new Uri("/Video.xaml", UriKind.Relative));
        }
    }
}